package com.zensun.web.controller.monitor;

import com.zensun.common.annotation.Log;
import com.zensun.common.core.controller.BaseController;
import com.zensun.common.core.domain.R;
import com.zensun.common.core.page.PageDataInfo;
import com.zensun.common.core.redis.RedisCache;
import com.zensun.common.enums.BusinessType;
import com.zensun.system.domain.SysLogininfor;
import com.zensun.system.domain.dto.SysLogininforDto;
import com.zensun.system.service.ISysLogininforService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 登录日志记录
 *
 * @author gmk
 */
@Api(value = "登录日志管理", tags = "登录日志模块")
@RestController
@RequestMapping("/monitor/logininfor")
public class SysLogininforController extends BaseController {
    @Autowired
    private ISysLogininforService logininforService;

    @Autowired
    private RedisCache redisCache;

    @ApiOperation("查询登录日志列表")
    @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public R<PageDataInfo<SysLogininfor>> list(SysLogininforDto logininforDto) {
        startPage();
        List<SysLogininfor> list = logininforService.list(logininforDto);
        return R.success(getPageDataTable(list));
    }

    @ApiOperation("查询个人登录日志列表")
    @GetMapping("/list/oneself")
    public R<PageDataInfo<SysLogininfor>> listOneSelf(SysLogininforDto logininforDto) {
        startPage();
        List<SysLogininfor> list = logininforService.listOneSelf(logininforDto);
        return R.success(getPageDataTable(list));
    }

    @ApiOperation("删除登录日志")
    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public R remove(@ApiParam("ID集合（1,2）") @PathVariable Long[] infoIds) {
        return R.toAjax(logininforService.deleteLogininforByIds(infoIds));
    }

    @ApiOperation("清空登录日志")
    @PreAuthorize("@ss.hasPermi('monitor:logininfor:clear')")
    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public R clean() {
        logininforService.cleanLogininfor();
        return R.success();
    }
}
